package com.lyf.viewapp.category.jdandtb.adapter;

import android.support.design.widget.Snackbar;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.lyf.viewapp.R;
import com.lyf.viewapp.category.jdandtb.bean.DrugItemBean;
import com.lyf.viewapp.category.jdandtb.bean.DrugListBean;
import com.lyf.viewapp.util.MyBaseViewHolder;
import com.zhy.view.flowlayout.FlowLayout;
import com.zhy.view.flowlayout.TagFlowLayout;

import java.util.List;

/**
 * User: Liumj(liumengjie@365tang.cn)
 * Date: 2016-10-11
 * Time: 15:51
 * describe:  右边适配器
 */
public class RightAdapter extends BaseQuickAdapter<DrugListBean, MyBaseViewHolder>{



	public RightAdapter(List<DrugListBean> data) {
		super(R.layout.jd_and_tb_item_main_right, data);
	}

	@Override
	protected void convert(final MyBaseViewHolder helper, DrugListBean item) {
		helper.setText(R.id.item_main_right_title,item.getType());
		TagFlowLayout  flowLayout = helper.getView(R.id.item_main_right_taglayout);
		final List<DrugItemBean> drugItemBeen = item.getmList();
		final DrugTagAdapter drugAdapter=new DrugTagAdapter(mContext,drugItemBeen);
		flowLayout.setAdapter(drugAdapter);
		flowLayout.setOnTagClickListener(new TagFlowLayout.OnTagClickListener() {
			@Override
			public boolean onTagClick(View view, int position, FlowLayout parent) {
				DrugItemBean drugItemBean = drugItemBeen.get(position);
				for (DrugItemBean b:
						drugItemBeen) {
					b.setCheck(false);
				}
				drugItemBean.setCheck(true);
				drugAdapter.notifyDataChanged();
				Snackbar.make(helper.itemView, "点击了"+drugItemBean.getName(), Snackbar.LENGTH_SHORT).show();
				return false;
			}
		});
	}
}
